package com.youlu.campus.web.pay;

import com.youlu.campus.entity.UserPO;
import com.youlu.campus.entity.VO.req.OrderConfirmComputePriceReq;
import com.youlu.campus.service.pay.PayV2Service;
import com.youlu.campus.web.common.base.RequestContext;
import com.yuelin.infrastructure.quantum.common.QResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 支付接口V2版本,2024-10-08
 */
@Slf4j
@RestController
public class PayV2Controller {
    @Autowired
    private PayV2Service payV2Service;

    /**
     * 获取订单确认页用户信息:手机号、地址等
     *
     * @param aid
     * @return
     */
    @GetMapping("/mini-app/v2/pay/order-confirm/ext-info")
    public QResult getOrderConfirmExtInfo(@RequestParam("activityId") String aid,
                                          @RequestParam(value = "mobile", required = false) String mobile,
                                          @RequestParam(value = "taskBizType", required = false)String bizType) {
        UserPO u=RequestContext.getCurUser();
        if(StringUtils.isNotBlank(mobile)){
            u.setMobile(mobile);
        }
        return QResult.success(payV2Service.getOrderConfirmInfo(u, aid,bizType));
    }

    /**
     * 订单确认页计算价格
     *
     * @param req
     * @return
     */
    @PostMapping("/mini-app/v2/pay/order-confirm/compute-price")
    public QResult computePrice(@RequestBody @NotNull OrderConfirmComputePriceReq req) {
        return QResult.success(payV2Service.computPrice(req));
    }
}
